package com.jqgrid.search.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jqgrid.search.result.Result;
import com.jqgrid.search.service.UserServcie;
import com.jqgrid.search.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(path = "/api/user")
public class DataController {


    @Autowired
    private UserServcie userServcie;

    @GetMapping("/index")
    @ResponseBody
    public Object getAll(HttpServletRequest request) {


        PageInfo<UserVo> pageInfo = userServcie.listUser(request);


        JSONObject oJson = new JSONObject();
        oJson.put("records", pageInfo.getTotal());
        oJson.put("total", pageInfo.getPageSize());
        oJson.put("rows", pageInfo.getList());
        oJson.put("page", pageInfo.getPageNum());

        return Result.success(oJson);
    }


}
